﻿using UnityEngine;
using System.Collections;

using System.Collections.Generic;

public class highScore : MonoBehaviour
{
	public List<int> highScoreint = new List<int> ();
	public int points;
	
	// Use this for initialization
	void Start ()
	{ 
		GetHighScore();
		
	}
	
	// Update is called once per frame
	void Update ()
	{
		if(Input.GetKeyDown(KeyCode.P)){
			UpdateHighScore(points);
		}
			
		if (Input.GetKeyDown(KeyCode.Space)){ //
			for(int i=0; i<highScoreint.Count; i++) { 
				highScoreint[i] = 0;
			}
		}
		
		if (Input.GetKeyDown(KeyCode.H)){
			GetHighScore();
		}
		
		Debug.Log("hej222"); 
		
	}

	void SetHighScore ()
	{
		for (int i=0; i<highScoreint.Count; i++) { //makes the highscore so you can put name and score in
			PlayerPrefs.SetInt ("Rank:" + (i + 1).ToString(), highScoreint [i]);
		}

		
	}
	
	void GetHighScore()
	{
		for (int i=0; i<highScoreint.Count; i++) {
			highScoreint[i] = PlayerPrefs.GetInt ("Rank:" + (i + 1).ToString());
		}
	}
	//giving new points to the list, 
	void UpdateHighScore(int points)
	{	
		for (int i=0; i<highScoreint.Count; i++){
			if (points >= highScoreint[i]){
				highScoreint.Insert(i,points);
				highScoreint.RemoveAt(highScoreint.Count-1);
				break;
				
			}
		}
		SetHighScore ();
	}	
	void OnGUI(){
		Debug.Log("hej"); 
		for(int i=0; i<highScoreint.Count; i++)
		{ 
		 
			GUI.Label(new Rect (115, 10 * i, 100, 20), (i+1).ToString () + ". " + highScoreint[i]);
		} 
	}
}

